#include "mythread.hpp"

// pthread_join调用结束
void *thread1(void *argv)
{
    int cut1 = 10;
    while (cut1)
    {
        std::cout << "child thread pid: " << getpid() << argv << std::endl;
        cut1--;
        sleep(1);
    }
    return (void *)100;
}

// 线程自己终止
void *thread2(void *argv)
{
    sleep(15);
    pthread_exit(0);
}

// 主线程终止
void *thread3(void *argv)
{
    sleep(100);
    return NULL;
}

// 线程自己分离
void *thread4(void *argv)
{
    pthread_detach(pthread_self());
    sleep(25);
    return NULL;
}

// 主线程分离
void *thread5(void *argv)
{
    sleep(30);
    return NULL;
}

int main()
{
    My_Thread::Thread myth1;
    My_Thread::Thread myth2;
    My_Thread::Thread myth3;
    My_Thread::Thread myth4;
    My_Thread::Thread myth5;

    myth5.Detach();

    // pthread_join调用结束
    myth1.Runing(thread1);
    // 线程自己终止
    myth2.Runing(thread2);
    // 主线程终止
    myth3.Runing(thread3);
    // 线程自己分离
    myth4.Runing(thread4);
    // 主线程分离
    myth5.Runing(thread5);

    sleep(20);
    myth3.Stop();

    sleep(15);
    void *ch1 = myth1.Join();

    myth2.Runing(thread1);
    myth2.Detach();


    return 0;
}
